<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>订单结算</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__STATIC_URL__/static/mobile/css/weui.css"/>
    <link rel="stylesheet" href="__STATIC_URL__/static/mobile/css/index.css"/>
    <style>
            a{
                color: #10aeff;
            }
            input {
                float: left;
                height: 50px;
                border-radius: 5px;
                font-size: 40px;
                text-align: left;
                width: 80%;
                border: 0px;
                font-weight: bold;
            }

            .wxpay_card {
                line-height: 45px;
                float: left;
            }

            .wxpay_card span {

                -webkit-background-size: 8.5px 13px;
                background-size: 8.5px 13px;
                padding: 10px 20px 9px 0;
                position: relative;
                font-size: 16px;
                min-height: 22px;
            }

            .wxpay_card a {
                text-decoration: none;
                color: #37c7da;
                font-size: 14px;
                position: absolute;
                right: -129px;
                width: 147px;
            }

            .clear {
                clear: both;
            }

            #card_pays {
                background-color: #0096e2;
                margin-top: 10px;
            }
    </style>
</head>

<body>
<div class="container" id="container">
    <br>
    <br>
    <div class="weui-form-preview">
        <div class="weui-form-preview__hd">
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">付款金额</label>
                <em class="weui-form-preview__value">¥{$cinfo['price']}</em>
            </div>
        </div>
        {if condition="$cinfo['Paycardinfo']['is_cardpay'] eq '2' "}
        <div class="weui-form-preview__hd">
            <div style="width: 100%;    position: relative;">
                {$cardinfo2}
                <div class="clear"></div>
            </div>
        </div>
        {/if}
        <div class="weui-form-preview__bd">
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">商品</label>
                <a href="{:url('cardshop/paycardsinfo',array('fid'=>$cinfo['fid'],'card_id'=>$card['card_id']))}">
                <span class="weui-form-preview__value">{$cinfo['Paycardinfo']['title']}</span>
                </a>
            </div>
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">订单编号</label>
                <span class="weui-form-preview__value">{$cinfo['orderid']}</span>
            </div>
        </div>
        <div class="weui-form-preview__hd">

        </div>
    </div>
    <div class="jine">

        <form action="" method="post">

            <div style="display:none;" id="qita">
                <input type="number" name="money" id="money" placeholder="充值金额(元)" min="0.1" max="9999" maxlength="4"/>

            </div>
            <ol class="weui-cells__title" type="1" id="czshow">

            </ol>
            <input type="hidden" id="id" value="{$cinfo['id']}">
            {eq name="cinfo['Paycardinfo']['is_wxpay']" value="2"}
            <a href="javascript:;" class="weui-btn weui-btn_primary" id="wxpay">微信支付</a>
            {/eq}
            {eq name="cinfo['Paycardinfo']['is_cardpay']" value="2"}
            <a href="javascript:;" class="weui-btn weui-btn_primary" id="card_pays">会员卡支付</a>
            {/eq}
        </form>
    </div>

</div>


<!----->
<div id="dialogt">
    <div class="js_dialog" id="iosDialog3" style="opacity: 1; display: none;">
        <div class="weui-mask">
        </div>
        <div class="weui-dialog">
            <div class="weui-dialog__bd">
                <div class="bgfff chakan" >
                    <p class="ku"></p>
                </div>
            </div>
            <div class="weui-dialog__ft">

                <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary">确认</a>
            </div>
        </div>
    </div>
</div>
</body>
<script src="__STATIC_URL__/static/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript" id="tpl_dialog">
    $(function(){
        var $iosDialog1 = $('#iosDialog1');
        var $iosDialog2 = $('#iosDialog2');
        $('#dialogs').on('click', '.weui-dialog__btn', function(){
            $(this).parents('.js_dialog').fadeOut(200);
        });
        $('#dialog').on('click', '.weui-dialog__btn', function(){
            $(this).parents('.js_dialog').fadeOut(200);
        });
        $('#dialogt').on('click', '.weui-dialog__btn', function(){
            $(this).parents('.js_dialog').fadeOut(200);
        });
        $('.showIOSDialog1').on('click', function(){
            $iosDialog1.fadeIn(200);
        });
        $('.showIOSDialog2').on('click', function(){
            $iosDialog2.fadeIn(200);
        });

        $(".cancel").click(function(){
            $(this).parent().attr("style","display:none");
        })
    });
</script>
<script>
    var pay_cate = "wx_pay";
    var pay_catename = "微信支付";
    $("#card_pays").click(function () {
        pay_cate = "card_pay";
        pay_catename = "会员卡支付";
        pay()

    });
    $("#wxpay").click(function () {
        pay_cate = "wx_pay";
        pay_catename = "微信支付";
        pay()

    });
</script>
<script type="text/javascript">

    var orderid = "{$cinfo['orderid']}";
    var id = $("#id").val();

    function pay() {

        $.ajax({
            url: "{:url('')}",
            type: 'post',
            dataType: 'json',
            data: {
                id: id,
                pay_type: pay_cate,
                orderid: orderid
            },

            success: function (data) {
                // console.log(12,data);

                if (pay_cate == "card_pay") {
                    if (data.code == 0) {
                        paysuccess();
                        $(".ku").html(data.message);
                        $("#iosDialog3").fadeIn(200);
                    } else {
                        $(".ku").html(data.message);
                        $("#iosDialog3").fadeIn(200);
                    }
                } else if (pay_cate == "wx_pay") {
                    if (typeof WeixinJSBridge == "undefined") {
                        if (document.addEventListener) {
                            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                        } else if (document.attachEvent) {
                            document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                        }
                    } else {
                        onBridgeReady(data);
                    }
                }


            }
        })


    }

    function onBridgeReady(sdata) {

        WeixinJSBridge.invoke(
            'getBrandWCPayRequest', sdata,
            function (res) {
                if (res.err_msg == "get_brand_wcpay_request:ok") {

                    paysuccess();
                }     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
                else if (res.err_msg == "get_brand_wcpay_request:fail") {
                    onBridgeReady();
                }
            }
        );

    };

    function paysuccess() {


        $.ajax({
            type: "POST",

            url: "{:url('Cardshoptest/paysuccess')}",

            cache: false,
            dataType: "json",
            async: false,
            data: {
                pay_type: pay_cate,
                id: "{$cinfo['mid']}",
                orderid: "{$cinfo['orderid']}",
            },

            success: function (data) {

                // console.log(11,data);
                if (data.code == 0) {

                    $(".ku").html(data.message);
                    $("#iosDialog3").fadeIn(200);

                    var url=data.data.url;
                    setTimeout(function(){ window.location.replace(url); },400)

                } else {

                    $(".ku").html(data.message);
                    $("#iosDialog3").fadeIn(200);
                }
            }


        });
    }


</script>
</html>